#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=50,MAXM=20;
int n,m,a[MAXN][MAXN],head[MAXN*MAXM],cnt,sum,ans,_x[]={0,1,-1,0,0},_y[]={0,0,0,1,-1},match[MAXN*MAXM];
bool vis[MAXN*MAXM];
struct edge
{
	int v,next;
}e[MAXN*MAXM*4];
void addedge(int x,int y)
{
	e[++cnt]=(edge){y,head[x]};
	head[x]=cnt;
	return;
}
bool Hungary(int x)
{
	for(int i=head[x];i;i=e[i].next)
	{
		int y=e[i].v;
		if(!vis[y])
		{
			vis[y]=true;
			if(!match[y]||Hungary(match[y]))
			{
				match[y]=x;
				return true;
			}
		}
	}
	return false;
}
int main()
{
	int T=read();
	while(T--)
	{
		memset(head,0,sizeof(head));
		memset(a,0,sizeof(a));
		memset(match,0,sizeof(match));
		cnt=sum=ans=0;
		n=read();m=read();
		for(int i=1;i<=n;++i)
		{
			char tmp[MAXM];
			scanf("%s",tmp+1);
			for(int j=1;j<=m;++j)
				if(tmp[j]=='*')
					a[i][j]=++sum;
		}
		for(int i=1;i<=n;++i)
			for(int j=1;j<=m;++j)
				if(a[i][j]&&(i+j)%2==0)
					for(int k=1;k<=4;++k)
						if(a[i+_x[k]][j+_y[k]])addedge(a[i][j],a[i+_x[k]][j+_y[k]]);
		for(int i=1;i<=sum;++i)
		{
			memset(vis,0,sizeof(vis));
			if(Hungary(i))++ans;
		}
		printf("%d\n",sum-ans);
	}
	return 0;
}
